<?php 
    include_once '../sql_connect.php'; 
    include_once '../msg_redirect.php';
    include_once '../timeConverter.php';
    include_once '../utilities/show_expression.php';
?>
<?php 
	/*重新载入主页微博内容*/
	/*循环输出weibo表的内容，同时输出头像，昵称，发布微博的时间*/
	$u_no = $_COOKIE['u_no'];
	$num = $_POST[weibo_num];
    $my_sql = mysql_query("SELECT weibo.u_no,w_content,w_date,u_name,h_id,w_id,t_id,p_id FROM weibo,user_info WHERE weibo.u_no IN(SELECT c_no FROM concerns WHERE u_no='$u_no' ) and user_info.u_no IN(SELECT c_no FROM concerns WHERE u_no='$u_no' ) and weibo.u_no=user_info.u_no ORDER BY w_date DESC LIMIT $num,20",$connection);
	$my_result = mysql_fetch_array($my_sql);
    $weibo_box_content = "";
    if($my_result){
    	do{
    		/*头标签*/
    		$weibo_box_content .= "<div class='weibo_box'>";	
    		$weibo_box_content .= "<span id='weibo_id' style='display:none'>".$my_result[w_id]."</span>";
    		
    		/*头像*/
    		$u_no = $my_result['u_no'];
   			$weibo_box_content .= "<div class='weibo_img'><a href='##'><img src='";
    		$show_head_sql = mysql_query("select h_data from head where u_no='$u_no'");
    		$show_head_result = mysql_fetch_array($show_head_sql);
    		$my_data = $show_head_result[h_data];
    		if (!$my_data){
    			$img = "head_image/09.jpg";
    		}
    		else {
    			$img = "$my_data";
    		}
   			$weibo_box_content .= $img."' width='50' height='50'/></a></div>";
   			
   			/*内容区头*/
    		$weibo_box_content .= "<div class='weibo_content'>"	;
    		
    		/*微博名*/			
        	$weibo_box_content .= "<font color='#06f'>".$my_result[u_name]."</font>: ";
	    	/*内容*/
        	$weibo_box_content .= show_expression($my_result[w_content]);
        	
        	##############################################################################
        	$t_id = $my_result[t_id];
        	if($t_id !="0"){
        		do{
        			$weibo_sql= mysql_query("SELECT weibo.u_no,w_content,w_date,u_name,h_id,w_id,t_id,p_id FROM weibo,user_info WHERE w_id='$t_id' AND user_info.u_no IN(SELECT u_no FROM weibo WHERE w_id='$t_id')");
        			$weibo_result2= mysql_fetch_array($weibo_sql);
        	
        			$t_id =$weibo_result2[t_id];
        			/*判断是不是最终的微博*/
        			if($t_id =="0"){ 
        				/*最终的微博,另开一个框*/
            			$weibo_box_content .= "<div class='weibo_t_content'><div class='weibo_t_bg'>";
	        			$weibo_box_content .= "<font color='#06f'>"."@".$weibo_result2[u_name]."</font>".": ".show_expression($weibo_result2[w_content]);
	        			$weibo_box_content .= "<div class='weibo_t_photo'><img";	        
			 			
	        			if($weibo_result2[p_id]!="0"){
							/*输出相片*/
        					$p_id= $weibo_result2['p_id'];
    						$photo_sql2 = mysql_query("select p_data from photo where p_id='$p_id'",$connection);
    						$photo_result2 = mysql_fetch_array($photo_sql2);
    						$my_data = $photo_result2[p_data];
    						$weibo_box_content .= "src='".$my_data."'width='150'";
						}
						$weibo_box_content .= "/></div>";
						
						$weibo_box_content .= "<div class='weibo_t_button'>转发(";
                        /*显示转发次数*/                     
                        $w_id = $weibo_result2[w_id];
                        /*检查weibo表中w_id（微博id）最大t_times（微博转发次数）*/
                        $weibo_sql = mysql_query("select t_times from weibo WHERE w_id = '$w_id'",$connection);	
                        $weibo_result = mysql_fetch_array($weibo_sql);
    					$weibo_data = $weibo_result[0];   						
    					$weibo_box_content .= $weibo_data.")&nbsp;|&nbsp;评论(";
    					/*显示评论次数*/                  
                        $w_id = $weibo_result2[w_id];
                        /*检查comment表中w_id（微博id）最大w_ctimes（微博评论次数）*/
                        $comment_sql = mysql_query("select MAX(w_ctimes) from comment WHERE w_id = '$w_id'",$connection);	
                        $comment_result = mysql_fetch_array($comment_sql);
    					$comment_data = $comment_result[0];  
    					if (!$comment_data){
    						$comment_data = 0;
    					}					
    					$weibo_box_content .= $comment_data.")</div>";
    					$weibo_box_content .= "<div class='weibo_t_time'>".timeConverter($weibo_result2[w_date])."</div><s><i></i></s></div></div>";
        			} 
        			else {	            
        				/*如果不是最终微博,则直接输出*/	       
        				$weibo_box_content .=  "<span class=''>";
	    				$weibo_box_content .=  "<font color='#06f'>"."@".$weibo_result2[u_name]."</font>".": ".show_expression($weibo_result2[w_content]);
	   					$weibo_box_content .=  " </span> ";	
        			}
        		}while($t_id);
        	}
	    	$weibo_box_content .= "</div>";

        $p_id= $my_result['p_id'];
        if($p_id!="0"){
        	$weibo_box_content .= "<div class='weibo_photo'><img src='";
        	/*输出相片*/
        	$p_id= $my_result['p_id'];
    		$photo_sql = mysql_query("select p_data from photo where p_id='$p_id'",$connection);
    		$photo_result = mysql_fetch_array($photo_sql);
    		$my_data = $photo_result[p_data];
    		$weibo_box_content .= $my_data."'width='150'/></div>";   
        
       }
        	##############################################################################
        	
	    	/*微博按钮*/
	  		$weibo_box_content .= "<div class='weibo_button'><a href='javascript:void(0);'>转发(";
	  		
	  		$w_id = $my_result[w_id];
            /*检查weibo表中w_id（微博id）最大t_times（微博转发次数）*/
            $weibo_sql = mysql_query("select t_times from weibo WHERE w_id = '$w_id'",$connection);	
            $weibo_result = mysql_fetch_array($weibo_sql);
    		$weibo_data = $weibo_result[0];
    		$weibo_box_content .= $weibo_data;
	  		$weibo_box_content .= ")</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='javascript:void(0);'>收藏</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='javascript:void(0);'>评论(";
	  		
	  		$w_id = $my_result[w_id];
            /*检查comment表中w_id（微博id）最大w_ctimes（微博评论次数）*/
            $comment_sql = mysql_query("select MAX(w_ctimes) from comment WHERE w_id = '$w_id'",$connection);	
            $comment_result = mysql_fetch_array($comment_sql);
    		$comment_data = $comment_result[0];
    		if (!$comment_data){
    			$comment_data = 0;
    		}	
    		$weibo_box_content .= $comment_data;
	  		$weibo_box_content .= ")</a></div>";
	  		
	  		/*发布时间*/
	  		$weibo_box_content .= "<div class='weibo_time'>".timeConverter($my_result[w_date])."</div>";
	  		
			/************************外层评论框*********************/
	  		$weibo_box_content .= "<div id='comment_box'><div class='comment_bg'>";
	  		$weibo_box_content .= "<span id='weibo_id' style='display:none'>".$my_result[w_id]."</span>";
	  		$weibo_box_content .= "<div contenteditable='true' type='text' name='comment_info' class='comment_info'></div>";
	  		$weibo_box_content .= "<input name='speach_submit' class='comment_submit' id='comment_submit' type='button' value='评 论'/>";
	  		
	  		/**********内层评论框*********/
	  		$weibo_box_content .= "<div class='comment_wrap'>";
	  		
	  		/*查询该微博的评论*/
	  		$comment_sql = mysql_query("SELECT c_id,c_content,c_date,u_no,r_id FROM comment WHERE w_id='$my_result[w_id]'",$connection);	
			$comment_result = mysql_fetch_array($comment_sql);
			if ($comment_result){
				do {
					if($comment_result[r_id]=="0"){
						$weibo_box_content .= "<div class='comment_sbox'><div class='comment_border'></div><div class='comment_img'><a href='##'><img src='";
						/*显示头像*/
        				$show_head_sql = mysql_query("select h_data from head where u_no='$comment_result[u_no]'",$connection);
    					$show_head_result = mysql_fetch_array($show_head_sql);
    					$my_data = $show_head_result[h_data];
    					if (!$my_data){
    						$weibo_box_content .= "head_image/09.jpg' width='30' height='30' border='0' /></a></div>";
    					}
    					else $weibo_box_content .= $my_data."'width='30' height='30' border='0' /></a></div>";
					
    					/*查询评论者昵称*/
						$show_user = mysql_query("select u_name from user_info where u_no = '$comment_result[u_no]'",$connection);
						$show_user_result = mysql_fetch_array($show_user);
						$weibo_box_content .= "<div class='comment_content'>".$show_user_result[u_name].":".$comment_result[c_content]."(".timeConverter($comment_result[c_date]).")</div>";
						$weibo_box_content .= "</div>";	/*comment_sbox结束*/
					}
					else {
						$weibo_box_content .= "<div class='comment_sbox'><div class='comment_border'></div><div class='comment_img'><a href='##'><img src='";
						/*显示头像*/
        				$show_head_sql = mysql_query("select h_data from head where u_no='$comment_result[u_no]'",$connection);
    					$show_head_result = mysql_fetch_array($show_head_sql);
    					$my_data = $show_head_result[h_data];
    					if (!$my_data){
    						$weibo_box_content .= "head_image/09.jpg' width='30' height='30' border='0' /></a></div>";
    					}
    					else $weibo_box_content .= $my_data."'width='30' height='30' border='0' /></a></div>";
    					$show_user = mysql_query("select u_name from user_info where u_no = '$comment_result[u_no]'",$connection);
						$show_user_result = mysql_fetch_array($show_user);
						$weibo_box_content .= "<div class='comment_content'>".$show_user_result[0].":";
						$comment_sql2= mysql_query("select u_name from user_info where u_no in(select u_no from comment where c_id='$comment_result[r_id]')",$connection);
						$comment_result2 = mysql_fetch_array($comment_sql2);
						$weibo_box_content .= "回复@".$comment_result2[u_name].":".$comment_result[c_content]."(".timeConverter($comment_result[c_date]).")";
						$weibo_box_content .= "</div></div>";
					}
				}
				while ($comment_result = mysql_fetch_array($comment_sql));
			}
	  		
	  		$weibo_box_content .= "</div>";	/*comment_wrap结束*/
	  		/***********************/
	  		
	  		$weibo_box_content .= "<s><i></i></s></div></div>";	/*comment_bg&comment_box结束*/
	  		/*****************************************************/
	  		
	  		/*水平线*/
        	$weibo_box_content .= "<div class='weibo_border'></div>";  

        	/*转发框*/
        	$weibo_box_content .= "<div id='zhuanfa_box'><span id='weibo_id' style='display:none'>".$my_result[w_id]."</span>";
        	$weibo_box_content .= "<div class='zhuanfa_titlebox'><div class='zhuanfa_title'>转发</div><div class='zhuanfa_close'><a href='javascript:void(0)'>关闭</a></div></div>";
        	$weibo_box_content .= "<div id='speach_expression' class='speach_image'><a href='javascript:void(0)'><img src='image/face.jpg' width='18' height='18'/></a></div>";
        	$weibo_box_content .= "<div class='zhuanfa_tips'>还能输入<span id='counter'>140</span>字</div>";
        	$weibo_box_content .= "<textarea name='zhuanfa_info' class='zhuanfa_info' id='zhuanfa_info'></textarea>";
        	$weibo_box_content .= "<input name='zhuanfa_submit' class='zhuanfa_submit' id='zhuanfa_submit' type='button' value='转 发' /></div>";
        	$weibo_box_content .= "<div id='transpond_face'><div class='face_title'>常用表情</div><div class='face_close'><a href='javascript:void(0)'>关闭</a></div><div class='face_content'>";
        	$tHead_sql = mysql_query("select * from expression",$connection);
    		$tHead_result = mysql_fetch_array($tHead_sql);
    		if($tHead_result){
    			do{
    				$weibo_box_content .= "<div class='face_img'><a href='javascript:void(0)'><img src='".$tHead_result[e_url]."' name='".$tHead_result[e_name]."'/></a></div>";
    			}
    			while($tHead_result = mysql_fetch_array($tHead_sql));
    		}
    		$weibo_box_content .= "</div></div></div>";
    	}
    	while ($my_result=mysql_fetch_array($my_sql));
 	}
 	
 	echo $weibo_box_content;
?>
